﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin.master" AutoEventWireup="true"
    CodeFile="ThietLapMuaBaoHiemTaiSan.aspx.cs" Inherits="ThietLapMuaBaoHiemTaiSan" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
<script language="javascript" type="text/javascript">
    function calculate() {
        var tong = document.getElementById("<%=txtGiaTriBH.ClientID %>").value;
        var bi = document.getElementById("<%=txtPhanTramBH.ClientID %>").value;
        
        if (tong == '') tong = "0";
        if (bi == '') bi = "0";

        tong = tong.replace(',', '').replace(',', '').replace(',', '');
        bi = bi.replace(',', '').replace(',', '').replace(',', '');

        var t1 = parseFloat(tong);
        var t2 = parseFloat(bi);

        document.getElementById("<%=txtTienSauThue.ClientID %>").value = ((t1 * t2) / 100).toFixed(1).replace(/\d(?=(\d{3})+\.)/g, '$&,');
        document.getElementById("<%=txtTienTruocThue.ClientID %>").value = (((t1 * t2) / 100) / 1.1).toFixed(1).replace(/\d(?=(\d{3})+\.)/g, '$&,');
    }
    function chietkhau() {
        var c1 = document.getElementById("<%=txtPhanTramChietKhau.ClientID %>").value;
        var c2 = document.getElementById("<%=txtTienTruocThue.ClientID %>").value;

        if (c1 == '') c1 = "0";
        if (c2 == '') c2 = "0";

        c1 = c1.replace(',', '').replace(',', '').replace(',', '');
        c2 = c2.replace(',', '').replace(',', '').replace(',', '');
        var m1 = parseFloat(c1);
        var m2 = parseFloat(c2);


        document.getElementById("<%=txtTTChietKhau.ClientID %>").value = ((m1 * m2) / 100).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
    }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <asp:UpdatePanel ID="up1" runat="server">
        <ContentTemplate>
            <div class="panel panel-success margin">
                <div class="panel-heading">
                    <h3 class="panel-title">
                        Quản lý mua bảo hiểm tài sản</h3>
                </div>
                <div class="panel-body">
                    <table width="100%">
                        <tr>
                            <td>
                                Tài sản cố định<br />
                                <asp:DropDownList ID="dlTaiSan" DataValueField="IDs" DataTextField="TenTaiSan" runat="server"
                                    CssClass="form-control with98">
                                </asp:DropDownList>
                                <asp:RequiredFieldValidator ValidationGroup="Them" ID="RequiredFieldValidator1" runat="server"
                                    ControlToValidate="dlTaiSan" ErrorMessage="Chọn tên tài sản" Display="None" Text="*"></asp:RequiredFieldValidator>
                            </td>
                            <td width="14%">
                                Nhãn hiệu<br />
                                <asp:TextBox runat="server" CssClass="form-control " ID="txtNhanHieu">
                                </asp:TextBox>
                            </td>
                            <td width="14%">
                                Đơn vị bán bảo hiểm<br />
                                <asp:DropDownList ID="dlBenBanBH" DataValueField="IDs" DataTextField="TenNCC" runat="server"
                                    CssClass="form-control with98">
                                </asp:DropDownList>
                                <asp:RequiredFieldValidator ValidationGroup="Them" ID="RequiredFieldValidator2" runat="server"
                                    ControlToValidate="dlBenBanBH" ErrorMessage="Chọn bên bán bảo hiểm" Display="None"
                                    Text="*"></asp:RequiredFieldValidator>
                            </td>
                            <td width="14%">
                                Hình thức mua<br />
                                <asp:TextBox runat="server" CssClass="form-control " ID="txtHinhThucMua">
                                </asp:TextBox>
                            </td>
                            <td width="14%">
                                Giá trị tham gia<br />
                                <asp:TextBox ID="txtGiaTriBH" CssClass="form-control " runat="server" onchange="calculate()"></asp:TextBox>
                                <cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" runat="server" FilterType="Custom,Numbers"
                                    TargetControlID="txtGiaTriBH" ValidChars=",." />
                            </td>
                            <td width="14%">
                                % bảo hiểm<br />
                                <asp:TextBox ID="txtPhanTramBH" CssClass="form-control " runat="server" onchange="calculate()"></asp:TextBox>
                                <cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender3" runat="server" FilterType="Custom,Numbers"
                                    TargetControlID="txtPhanTramBH" ValidChars=",." />
                            </td>
                            <td width="14%">
                                Thành tiền sau thuế<br />
                                <asp:TextBox ID="txtTienSauThue" Enabled="false" CssClass="form-control " runat="server"></asp:TextBox>
                                <cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender2" runat="server" FilterType="Custom,Numbers"
                                    TargetControlID="txtTienSauThue" ValidChars=",." />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Thành tiền trước thuế<br />
                                <asp:TextBox ID="txtTienTruocThue" Enabled="false" CssClass="form-control " runat="server"></asp:TextBox>
                                <cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender4" runat="server" FilterType="Custom,Numbers"
                                    TargetControlID="txtTienTruocThue" ValidChars=",." />
                            </td>
                            <td width="14%">
                                % Chiết khấu<br />
                                <asp:TextBox ID="txtPhanTramChietKhau" CssClass="form-control " runat="server" onchange="chietkhau()"></asp:TextBox>
                                <cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender5" runat="server" FilterType="Custom,Numbers"
                                    TargetControlID="txtPhanTramChietKhau" ValidChars=",." />
                            </td>
                            <td width="14%">
                                Thành tiền chiết khấu<br />
                                <asp:TextBox ID="txtTTChietKhau" Enabled="false" CssClass="form-control " runat="server"></asp:TextBox>
                                <cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender6" runat="server" FilterType="Custom,Numbers"
                                    TargetControlID="txtTTChietKhau" ValidChars=",." />
                            </td>
                            <td width="14%">
                                Từ ngày<br />
                                <asp:TextBox runat="server" CssClass="form-control " ID="txtTuNgay">
                                </asp:TextBox>
                                <cc1:CalendarExtender PopupPosition="BottomRight" ID="CalendarExtender6" runat="server"
                                    TargetControlID="txtTuNgay" Format="dd/MM/yyyy">
                                </cc1:CalendarExtender>
                                <cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender7" runat="server" FilterType="Custom,Numbers"
                                    TargetControlID="txtTuNgay" ValidChars="/" />
                            </td>
                            <td width="14%">
                                <span style="margin-left: 5px;">Đến ngày</span>
                                <br />
                                <asp:TextBox runat="server" CssClass="form-control " ID="txtDenNgay">
                                </asp:TextBox>
                                <cc1:CalendarExtender PopupPosition="BottomRight" ID="CalendarExtender7" runat="server"
                                    TargetControlID="txtDenNgay" Format="dd/MM/yyyy">
                                </cc1:CalendarExtender>
                                <cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender8" runat="server" FilterType="Custom,Numbers"
                                    TargetControlID="txtDenNgay" ValidChars="/" />
                            </td>
                            <td>
                                <br />
                                <asp:CheckBox ID="ckDaTra" runat="server" Text="Đã trả" />
                                <asp:CheckBox ID="ckDaThu" runat="server" Text="Đã nhận triết khấu" AutoPostBack="true"
                                    oncheckedchanged="ckDaThu_CheckedChanged" />
                            </td>
                            <td>
                                <br />
                                
                                 <asp:DropDownList ID="drkhach" DataValueField="IDs" DataTextField="tenkhachhang" runat="server"
                                    CssClass="form-control with98">
                                </asp:DropDownList>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="7">
                                <asp:Button ID="btnSave" ValidationGroup="Them" runat="server" Style="margin-left: 5px;"
                                    Text="Lưu lại" CssClass="btn btn-primary" onclick="btnSave_Click" />
                                <asp:Button ID="btncapnhat" runat="server" Text="Cập nhật" CssClass="btn btn-info"
                                    Visible="false" onclick="btncapnhat_Click" />
                                <asp:Button ID="btnCancel" runat="server" Text="Nhập mới" 
                                    CssClass="btn btn-warning" onclick="btnCancel_Click" />
                            </td>
                        </tr>
                    </table>
                    <asp:ValidationSummary ID="ValidationSummary1" HeaderText="Bạn phải nhập các trường sau:"
                        ShowMessageBox="true" ValidationGroup="Them" ShowSummary="false" EnableClientScript="true"
                        runat="server" />
                </div>
            </div>
            <div style="margin: 5px;">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        Danh sách mua bảo hiểm tài sản
                        <asp:Button ID="btnPrint" runat="server" Text="Xuất báo cáo" CssClass="btn btn-primary"
                            OnClick="btnPrint_Click" />
                        </div>
                    
                    <div style="width: 100%; margin-top: 10px; overflow: auto;" class="wrapper">
                        <div style="width: 100%; max-height: 300px;">
                            <asp:GridView ID="GV" runat="server" AutoGenerateColumns="false" BackColor="White"
                                BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="1" EmptyDataText="Không có dữ liệu nào"
                                EnableModelValidation="True" ShowFooter="false" CssClass="form-control withall"
                                Width="99%" onrowcommand="GV_RowCommand">
                                <Columns>
                                    <asp:TemplateField HeaderText="Xóa" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="50px"
                                        ItemStyle-Width="50px">
                                        <ItemTemplate>
                                            <asp:ImageButton ID="lbXoa" runat="server" Width="20px" Height="20px" ImageUrl="~/img/delete-24.png"
                                                OnClientClick="return confirm('Bạn chắc chắn muốn xóa ?')" CommandArgument='<%#Eval("IDs")%>'
                                                Text="Xóa" CommandName="Del" />
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Sửa" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="50px"
                                        ItemStyle-Width="50px">
                                        <ItemTemplate>
                                            <asp:ImageButton ID="lbSua" runat="server" Width="15px" Height="15px" ImageUrl="~/img/edit.ico"
                                                CommandArgument='<%#Eval("IDs")%>' Text="Sửa" CommandName="Select" />
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:BoundField DataField="TaiSan" ItemStyle-CssClass="padding" HeaderText="Tài sản"
                                        HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Left" />
                                    <asp:BoundField DataField="NhanHieu" ItemStyle-CssClass="padding" HeaderText="Nhãn hiệu"
                                        HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Left" />
                                    <asp:BoundField DataField="BenBanBH" ItemStyle-CssClass="padding" HeaderText="Bên bán BH"
                                        HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Left" />
                                    <asp:BoundField DataField="HinhThucMua" ItemStyle-CssClass="padding" HeaderText="Hình thức mua"
                                        HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Left" />
                                    <asp:BoundField DataField="GiaTriBH" ItemStyle-CssClass="padding" HeaderText="Giá trị BH"
                                        HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Right" DataFormatString="{0:0,0}" />
                                    <asp:BoundField DataField="PhanTramBH" ItemStyle-CssClass="padding" HeaderText="% BH"
                                        HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" />
                                    <asp:BoundField DataField="TTSauThue" ItemStyle-CssClass="padding" HeaderText="TT sau thuế"
                                        HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Right" DataFormatString="{0:0,0}" />
                                    <asp:BoundField DataField="TTTruocThue" ItemStyle-CssClass="padding" HeaderText="TT trước thuế"
                                        HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Right" DataFormatString="{0:0,0}" />
                                        
                                   <asp:BoundField DataField="PhanTramChietKhau" ItemStyle-CssClass="padding" HeaderText="% CK"
                                        HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" />
                                        <asp:BoundField DataField="TTChietKhau" ItemStyle-CssClass="padding" HeaderText="TT chiết khấu"
                                        HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Right" DataFormatString="{0:N3}" />
                                        <asp:BoundField DataField="TuNgay" ItemStyle-CssClass="padding" HeaderText="Từ ngày"
                                        HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" />
                                        <asp:BoundField DataField="DenNgay" ItemStyle-CssClass="padding" HeaderText="Đến ngày"
                                        HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" />
                                        
                                        <asp:BoundField DataField="DaTraBH" ItemStyle-CssClass="padding" HeaderText="Đã trả BH"
                                        HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" />
                                        <asp:BoundField DataField="DaNhanChietKhau" ItemStyle-CssClass="padding" HeaderText="Đã nhận CK"
                                        HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" />
                                </Columns>
                                <FooterStyle BackColor="White" ForeColor="#000066" Font-Bold="True" HorizontalAlign="Left" />
                                <HeaderStyle BackColor="White" Font-Bold="True" ForeColor="Black" Height="30px" />
                                <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
                                <RowStyle BackColor="White" ForeColor="#000066" Height="30px" />
                                <SelectedRowStyle BackColor="Lavender" Font-Bold="false" />
                            </asp:GridView>
                        </div>
                    </div>
                </div>
                <asp:HiddenField ID="hdID" runat="server" />
                <asp:HiddenField ID="hdatra" runat="server" />
                <asp:HiddenField ID="hdathu" runat="server" />
            </div>
        </ContentTemplate>
        <Triggers>
            <asp:PostBackTrigger ControlID="btnPrint" />
        </Triggers>
    </asp:UpdatePanel>
</asp:Content>
